Unix [Homework]: Get a list of /home/user/ directories in /etc/passwd
Posted
by KChaloux
on Stack Overflow
See other posts from Stack Overflow
or by KChaloux
Published on 2010-03-29T05:07:47Z
Indexed on
2010/03/29
5:13 UTC
Read the original article
Hit count: 748
I'm very new to Unix, and currently taking a class learning the basics of the system and its commands.
I'm looking for a single command line to list off all of the user home directories in alphabetical order from the /etc/passwd directory. This applies only to the home directories, and not the contents within them. There should be no duplicate entries. I've tried many permutations of commands such as the following:
sort -d | find /etc/passwd /home/* -type -d | uniq | less
I've tried using -path, -name, removing -type, using -prune, and changing the search pattern to things like /home/*/$, but haven't gotten good results once. At best I can get a list of my own directory (complete with every directory inside it, which is bad), and the directories of the other students on the server (without the contained directories, which is good). I just can't get it to display the /home/user directories and nothing else for my own account.
Many thanks in advance.
© Stack Overflow or respective owner